<?php
namespace Systemht\Model;
use Think\Model;
class PictModel extends Model{
	protected $insertField = array('name','cate_id','sort','image1','image','link','desc');
	protected $updateField = array('id','old_image','sort','image1','name','cate_id','image','link','desc');
	protected $_validate = array(
		array('name','require','栏目名称不能为空'),
		);
	protected function _before_insert(&$data,$option){
		$data['ctime'] = time();
		$image1 = I('post.image1');
		if(!empty($image1)){
			$data['image'] = $image1;
		}
		else if(isset($_FILES['image']) && $_FILES['image']['error'] == 0){
            $data['image'] = uploadImage('image');
        }
	}
	protected function _before_update(&$data,$option){
		$image1 = I('post.image1');
		if(!empty($image1)){
			$data['image'] = $image1;
		}
		else if(isset($_FILES['image']) && $_FILES['image']['error'] == 0){
            $data['image'] = uploadImage('image');
            delImage(I('post.old_image'));
        }
	}
}